package main

import (
	"fmt"
	"io"
	"net/http"
)

func rrCookie() {
	Client := &http.Client{
		CheckRedirect: func(req *http.Request, via []*http.Request) error {
			return http.ErrUseLastResponse
		},
	}
	//模拟一个登录
	r, _ := http.Get("http://httpbin.org/cookies/set?freeform=name&name=21")
	defer func() {
		_ = r.Body.Close()
	}()
	r2, _ := http.NewRequest(http.MethodGet, "http://httpbin.org/cookies", nil)

	secondResonse, _ := Client.Do(r2)
	for _, cookie := range r.Cookies() {
		r2.AddCookie(cookie)
	}
	b, _ := io.ReadAll(secondResonse.Body)
	fmt.Println(string(b))
	for _, cookie := range r2.Cookies() {
		fmt.Println("cookie = ", cookie)
	}

}

//cookie
func main() {
	rrCookie()
}
